<script type="text/javascript">
    function login_validate()
    {
        var email = document.getElementById('email').value;
        var password = document.getElementById('password').value;
        
        if(email == '')
        {
            document.getElementById("error").innerHTML="Bạn chưa điền đầy đủ thông tin";
            return false;
        }
        else if(email.length > 100)
        {
            document.getElementById("error").innerHTML="Email tối đa 100 kí tự";
            return false;
        }
        else
        {
            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            if(reg.test(email) == false)
            {
                document.getElementById("error").innerHTML="Địa chỉ email không hợp lệ";
                return false;
            }
        }
        if(password == '')
        {
            document.getElementById("error").innerHTML="Bạn chưa điền đầy đủ thông tin";
            return false;
        }
        else
        {
            if((password.length < 6) || (password.length > 32))
            {
                document.getElementById("error").innerHTML="Mật khẩu độ dài 6-32 kí tự";
                return false;
            }
        }
        
    }
     function dolog(){ 
            username = document.getElementById('email').value;
            pass = document.getElementById('password').value;
            if(document.getElementById('rememberMe').checked == true){
                rememberMe = 1;
            }
            else {
                rememberMe = 0;
            }

            $.ajax({ 
                url: "<?php echo $this->baseUrl('library/login.php')?>", 
                type: "post",                
                data: "email="+username+'&password='+pass+'&rememberMe='+rememberMe,
                cache: false,                
                async :false, 
                success :function(result){
                    if (result !='')
                    {
                        $('#login_register').html('<a href="<?php echo $this->baseUrl('user');?>" style="border:none;">' + username + '</a>&nbsp;|&nbsp;<a href="<?php echo $this->baseUrl('index/logout');?>" onclick="logout()">Thoát</a>');
                        //$('.btnthoat_header').html('Thoát');          
                        tb_remove();
                    }
                     else
                     {
                        document.getElementById('password').value = '';
                       $('.error').html('Địa chỉ email hoặc mật khẩu sai ') ;
                     }
                } 
            });
        } 
</script>
<div class="loginform" style="width: 290px; height: 200px; padding-left: 15px;">
    <form action="javascript:dolog();" method="post" onsubmit="return login_validate()" >
    <input type="hidden" name="clr" id="clr" />
        <div style=" margin: 10px 0 0 10px; line-height: 25px;">
            <label for="email" style="font-size: 10pt;color: black; font-weight: bold;">Địa chỉ Email</label><br />
            <?php echo $this->formText('email', $this->emailValue, array('id' => 'email', 'class' => 'input', 'style' => 'width: 250px; height:13px;')); ?>
        </div>
            <div style=" margin: 10px 0 0 10px; line-height: 25px;">
            <label for="password" style="font-size: 10pt;color: black; font-weight: bold;">Mật khẩu</label><br />
            <?php echo $this->formPassword('password', null, array('id' => 'password', 'class' => 'input', 'style' => 'width: 250px; height:13px;')); ?>
        </div>
        <div style=" margin: 10px 0 0 10px; line-height: 25px;">                             
            <a style="color: black;" href="<?php echo $this->baseUrl('index/forgotpassword'); ?>">Quên mật khẩu?</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="checkbox" id="rememberMe" name="rememberMe" />
            <?php echo $this->formLabel('rememberMe', 'Lưu thông tin đăng nhập', array('style' => 'margin-left: 10px; color:black;')); ?>                               
        </div>
        <div style="text-align: center; margin-top:10px;">
             <?php echo $this->formSubmit('submit', 'Đăng nhập', array('class' => 'button', 'style' => 'float: left; margin-left: 50px'));?>&nbsp;&nbsp;&nbsp;&nbsp;
             <?php echo $this->formButton('button', 'Thoát', array('class' => 'button','onclick'=>'tb_remove()', 'style' => 'float: left; position: relative; margin-left: 10px'));?>             
         </div>
       <div class="error" id="error" style="clear: both; text-align: center; margin-top: 25px">
              
       </div>
    </form>
</div>